package com.iphanta.community.activity;

import com.iphanta.community.activity.photographic.common.BallBoxCollection;
import com.iphanta.community.cache.ActivityCache;
import com.iphanta.community.remote.common.RemoteResult;
import com.iphanta.community.remote.feign.ActivityFeign;
import com.iphanta.community.remote.traffic.AllActivityResponse;
import com.iphanta.community.remote.traffic.vo.ActivityInfo;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * @author 墨声 E-mail: zehong.hongframe.huang@gmail.com
 * create time: 4/14/22 2:27 PM
 */
//@Component
public class ActivityApplicationRunner implements ApplicationRunner {

    @Autowired
    private ActivityFeign activityFeign;

    @Autowired
    private RedissonClient redissonClient;

    @Autowired
    private ActivityCache activityCache;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        RemoteResult<AllActivityResponse> result = this.activityFeign.allActivity();
        AllActivityResponse response = result.getData();
        for (ActivityInfo info : response.getActivityInfos()) {
            this.activityCache.put(info.getActivityId(),
                    new BallBoxCollection(redissonClient, info.getActivityId()));
        }
    }
}
